*********************************************************************
*** Political costs of trade war tariffs 
*** Edward D. Mansfield & Omer Solodoch 
*** Replication code for analysis of pooled data  
*** Note: replicators must install the following packages from the SSC Archive:
*** ssc install ebalance
*** ssc install outtable
*** ssc install coefplot
*** ssc install esttab
*** ssc install scheme_rbn1mono
*********************************************************************
clear all
set mem 600m
set matsize 800	
version 17
set more off
set logtype text
set scheme s1mono
*** Set working directory
capture cd "XXXX"
*** Load dataset
use "MSJOP_pooled.dta", clear

*********************************************************************************
** define sample restricted to observations with non-missing values in covariates
reg TRUMPAPP1 China_tariffs_June16 female i.AGEA collgrad income_75 race2 race3 race4 partisan2 
gen sample_cov = e(sample)

**********************************************************
** Table A-4: pooled and re-weighted (using entropy balancing) sample
**********************************************************
qui ebalance China_tariffs_June16 female i.AGEA collgrad income_75 partisan2 partisan3 race2 race3 race4
estimates clear
** (1)
eststo: reg TRUMPAPP1 China_tariffs_June16  if sample_cov==1
estadd local ebln "", replace
estadd local controls "", replace
estadd local sfixedef "", replace
** (2)
eststo: reg TRUMPAPP1 China_tariffs_June16 female i.AGEA collgrad income_75 partisan2 partisan3 race2 race3 race4, robust
estadd local ebln "", replace
estadd local controls "\checkmark", replace
estadd local sfixedef "", replace
** (3)
eststo: reg TRUMPAPP1 China_tariffs_June16 female i.AGEA collgrad income_75 partisan2 partisan3 race2 race3 race4 [aweight=_webal], robust
estadd local ebln "\checkmark", replace 
estadd local controls "\checkmark", replace
estadd local sfixedef "", replace
** (4)
eststo: areg TRUMPAPP1 China_tariffs_June16 female i.AGEA collgrad income_75 partisan2 partisan3 race2 race3 race4 [aweight=_webal], absorb(State) robust
estadd local ebln "\checkmark", replace
estadd local controls "\checkmark", replace
estadd local sfixedef "\checkmark", replace

** export table
 esttab est1 est2 est3 est4, keep(China_tariffs_June16) ///
order(China_tariffs_June16) ///
 se(3) b(3) replace star(+ 0.10 * 0.05 ** 0.01) label nonotes nogaps  ///
 nodepvars mtitles("" "" "" "") ///
 s(controls ebln sfixedef N r2, fmt(0 0 0 0 3) label("Covariates" "Reweighted sample" "State FE" "Observations" "R-squared"))

********************************************************************
** Figure A-4: Trump's job approval rating by day
********************************************************************
set scheme s1mono
preserve
foreach var in TRUMPAPP1 {
bysort day: gen `var'_N = _N
egen `var'_m = mean(`var'), by(day)
egen `var'_sd = sd(`var'), by(day)
gen `var'_se   = `var'_sd/sqrt(`var'_N)
gen `var'_lower   = `var'_m-(`var'_se*1.96)
gen `var'_upper   = `var'_m+(`var'_se*1.96)
}
contract TRUMPAPP1_N TRUMPAPP1_m  TRUMPAPP1_lower TRUMPAPP1_upper  day
 sort day
 twoway scatter TRUMPAPP1_m day, lpattern(solid) msymbol(o) msize(vlarge) col(black) ///
 || line TRUMPAPP1_m day, lpattern(solid) lc(black) ///
   ||  rcap TRUMPAPP1_upper TRUMPAPP1_lower day , lpattern(dash) lc(black) ///
 yti("Trump's Job Approval Rating") ///
 legend(off) yscale(nofextend) xscale(nofextend) ///
 ylabel(0(0.1)0.8, angle(horizontal)) xlabel(11(1)20, angle(horizontal)) xscale(r(10 21)) ///
 xline(15.5, lc(maroon) lp(dash))  /// yline(.4511743, lc(black)) yline(.3579418, lc(black)
 xti("Day in June 2018") xline(0, lpattern(solid) lc(gs12) lstyle(foreground)) 
restore

********************************************************************
** Figure A-5: Effect by party id and sample
********************************************************************
** (a) Pooled sample
********************************************************************
set scheme rbn3mono
areg TRUMPAPP1 China_tariffs_June16##i.partyid i.income_75 i.SEX i.AGEA collgrad female [aw=weight], absorb(State) 
margins, dydx(China_tariffs_June16) at(partyid=(1(1)3))
marginsplot, plotopts(msize(vlarge)) ciopts(lwidth(medthick)) yline(0, lp(dash) lc(maroon)) xlabel(3 "Republican" 1 "Democrat" 2 "Independent", angle(horizontal) labsize(medium)) level(95) recast(scatter) xscale(range(0.5 3.5)) xt("") yt("Post-escalation effect on Trump approval", size(medium)) yscale(range(-0.3 0.1) titlegap(*-30)) ylabel(-0.3(0.1)0.1, labsize(medium)) title("") legend(off)

********************************************************************
** (b) CBS sample
********************************************************************
areg TRUMPAPP1 China_tariffs_June16##i.partyid i.income_75 i.SEX i.AGEA collgrad female [aw=weight] if survey==1, absorb(State) 
margins, dydx(China_tariffs_June16) at(partyid=(1(1)3))
marginsplot, plotopts(msize(vlarge)) ciopts(lwidth(medthick)) yline(0, lp(dash) lc(maroon)) xlabel(3 "Republican" 1 "Democrat" 2 "Independent", angle(horizontal) labsize(medium)) level(95) recast(scatter) xscale(range(0.5 3.5)) xt("") yt("Post-escalation effect on Trump approval", size(medium)) yscale(range(-0.3 0.1) titlegap(*-30)) ylabel(-0.3(0.1)0.1, labsize(medium)) title("") legend(off)

********************************************************************
** (c) KFF sample
********************************************************************
areg TRUMPAPP1 China_tariffs_June16##i.partyid i.income_75 i.SEX i.AGEA collgrad female [aw=weight] if survey==2, absorb(State)  
margins, dydx(China_tariffs_June16) at(partyid=(1(1)3))
marginsplot, plotopts(msize(vlarge)) ciopts(lwidth(medthick)) yline(0, lp(dash) lc(maroon)) xlabel(3 "Republican" 1 "Democrat" 2 "Independent", angle(horizontal) labsize(medium)) level(95) recast(scatter) xscale(range(0.5 3.5)) xt("") yt("Post-escalation effect on Trump approval", size(medium)) yscale(range(-0.3 0.1) titlegap(*-30)) ylabel(-0.3(0.1)0.1, labsize(medium)) title("") legend(off)

